package blog.service.impl;

import blog.dao.UserDao;
import blog.pojo.User;
import blog.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User selectById(Integer id) throws Exception {
        return userDao.selectById(id);
    }

    @Override
    public User selectByName(String name) throws Exception {
        return userDao.selectOne(new QueryWrapper<>(new User().setName(name)));
    }

    @Override
    public Boolean updatePassword(String name, String newPassword) throws Exception {
        return userDao.update(
            new User().setPassword(newPassword),
            new QueryWrapper<>(new User().setName(name))
        ) > 0;
    }
}
